/**
 * Applikationsutveckling i Java, 5DV135
 * HT12
 * Project
 * 
 * File: TowerTest.java
 * Description: A JUnitTestCaseClass used to test the class Tower
 * Date: 18 december 2012
 * 
 * cs-user: dv11mgr
 * @author Maria Gramner
 */

package nullInvader.Test;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import nullInvader.Engine.Road;
import nullInvader.Engine.Tower;
import nullInvader.Engine.Unit;
import nullInvader.Engine.Zone;
import junit.framework.TestCase;


public class TowerTest extends TestCase {

	Tower tower;
	ArrayList<Zone> reachables;
	Road road1, road2;
	Zone zone1, zone2;


	/**
	 * Test for the constructor
	 */
	public void testConstruction(){
		Tower tower = new Tower(false, -15, 4, new Point()){
			protected void setIcon(){}
			public void wasClicked(){}
			public void landOn(Unit unit){}
			public Image getIcon() {
				return null;
			}
		};
		/*Checks that a tower was made*/
		assertNotNull(tower);
	}


	/**
	 * setUp method that creates the necessary objects
	 * for testing correctly
	 */
	public void setUp(){
		tower = new Tower(false, -15, 4, new Point()){
			protected void setIcon(){}
			public void wasClicked(){}
			public void landOn(Unit unit){}
			public Image getIcon() {
				return null;
			}
		};

		reachables = new ArrayList<Zone>();
		road1 = new Road(true);
		road2 = new Road(true);
		zone1 = new Zone(road1);
		zone2 = new Zone(road2);
		reachables.add(zone1);
		reachables.add(zone2);

		tower.setReachableZones(reachables);
	}


	/**
	 * Tests that both method setReachableZones() and getReachableZones()
	 * works correctly
	 */
	public void testSetGetReachableZones(){
		ArrayList<Zone> reachables = new ArrayList<Zone>();
		ArrayList<Zone> tempList;
		tower.setReachableZones(reachables);
		tempList = tower.getReachableZones();
		/*Checks that the correct list was set and returned*/
		assertEquals(reachables, tempList);
	}


	/**
	 * Checks that the method getRange works correctly
	 */
	public void testGetRange1(){
		/*The range is currently 4*/
		assertEquals(tower.getRange(), 4);
	}


	/**
	 * Checks that the method getRange works correctly
	 */
	public void testGetRange2(){
		tower = new Tower(false, -15, 7, new Point()){
			protected void setIcon(){}
			public void wasClicked(){}
			public void landOn(Unit unit){}
			public Image getIcon() {
				return null;
			}
		};
		/*The range is currently 7*/
		assertEquals(tower.getRange(), 7);
	}


	/**
	 * Tests that the method takeShot works correctly
	 * when there are no targets nearby
	 */
	public void testTakeShot(){
		boolean works = false;
		/*Makes sure that the method doesn't crash
		  when there are no targets*/
		try{
			tower.takeShot();
			works = zone1.getUnitList().isEmpty();
		}catch(Exception e){
		}
		/*If the boolean works is true, the method worked*/
		assertTrue(works);
	}


	/**
	 * tearDown method
	 */
	public void tearDown(){
		tower = null;
		reachables = null;
		road1 = null;
		road2 = null;
		zone1 = null;
		zone2 = null;
	}
}
